package com.atguigu.gmall.payment.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/***
 * 订单支付结果通知的消息队列配置
 */
@Configuration
public class OrderPayRabbitConfig {

    /**
     * 订单支付的交换机
     */
    @Bean("orderPayExchange")
    public Exchange orderPayExchange() {
        return ExchangeBuilder.directExchange("order_pay_exchange").build();
    }

    /**
     * 普通订单支付的队列
     */
    @Bean("orderPayNormalQueue")
    public Queue orderPayNormalQueue() {
        return QueueBuilder.durable("order_pay_normal_queue").build();
    }

    /**
     * 秒杀订单支付的队列
     */
    @Bean("orderPaySeckillQueue")
    public Queue orderPaySeckillQueue() {
        return QueueBuilder.durable("order_pay_seckill_queue").build();
    }

    /**
     * 秒杀订单队列与交换机进行绑定
     */
    @Bean
    public Binding orderPaySeckillbinding(@Qualifier("orderPayExchange") Exchange orderPayExchange,
                                          @Qualifier("orderPaySeckillQueue") Queue orderPaySeckillQueue) {
        return BindingBuilder.bind(orderPaySeckillQueue).to(orderPayExchange).with("order.seckill.pay").noargs();
    }

    /**
     * 普通订单队列与交换机进行绑定
     */
    @Bean
    public Binding binding(@Qualifier("orderPayExchange") Exchange orderPayExchange,
                           @Qualifier("orderPayNormalQueue") Queue orderPayNormalQueue) {
        return BindingBuilder.bind(orderPayNormalQueue).to(orderPayExchange).with("order.normal.pay").noargs();
    }

}
